/**
 * 
 */
package com.pengtu.entity.detect.grade;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;


import com.pengtu.entity.IdEntity;
import com.pengtu.utils.MathsUtils;

/**
 * @author Administrator
 * 
 */
@Entity
@Table(name="T_Q_GRADE_UNITPROJ")
public class UnitProj extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String unitProjName;
	private String unitProjCode;
	private Double unitProjPrice;
	private String pathName;
	private String workArea;
	private String quaLevel;
	private Double unitProjPoint;
	private String remark;
	private SignProjQuaCheck signQuaCheck;
	private List<Branch> branchList = new ArrayList<Branch>();

	@Column(name="UNITPROJNAME")
	public String getUnitProjName() {
		return unitProjName;
	}

	public void setUnitProjName(String unitProjName) {
		this.unitProjName = unitProjName;
	}

	@Column(name="UNITPROJCODE")
	public String getUnitProjCode() {
		return unitProjCode;
	}

	public void setUnitProjCode(String unitProjCode) {
		this.unitProjCode = unitProjCode;
	}


	@Column(name="PRICE")
	public Double getUnitProjPrice() {
		return unitProjPrice;
	}

	public void setUnitProjPrice(Double unitProjPrice) {
		this.unitProjPrice = unitProjPrice;
	}

	
	@Column(name="PATHNAME")
	public String getPathName() {
		return pathName;
	}

	public void setPathName(String pathName) {
		this.pathName = pathName;
	}
	
	@Column(name="WORKAREA")
	public String getWorkArea() {
		return workArea;
	}

	public void setWorkArea(String workArea) {
		this.workArea = workArea;
	}
	
	@Column(name="QUALEVEL")
	public String getQuaLevel() {
		return quaLevel;
	}

	public void setQuaLevel(String quaLevel) {
		this.quaLevel = quaLevel;
	}

	@Column(name="UNITPROJPOINT")
	public Double getUnitProjPoint() {
		return unitProjPoint;
	}

	public void setUnitProjPoint(Double unitProjPoint) {
		this.unitProjPoint = unitProjPoint;
	}

	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany
	@JoinColumn(name="UNITPROJID")
	public List<Branch> getBranchList() {
		return branchList;
	}

	public void setBranchList(List<Branch> branchList) {
		this.branchList = branchList;
	}
	
	@ManyToOne(cascade=CascadeType.REMOVE)
	@JoinColumn(name="SIGNPROJID")
	public SignProjQuaCheck getSignQuaCheck() {
		return signQuaCheck;
	}

	public void setSignQuaCheck(SignProjQuaCheck signQuaCheck) {
		this.signQuaCheck = signQuaCheck;
	}

	//获得单位工程下抽查项目总数
	@Transient
	public Integer getSubentryTotal(){
		int total = 0;
		for (Branch branch : this.getBranchList()) {
			total += branch.getSubentryList().size();
		}
		return total;
	}
	
	
	//获取优良单位工程数
		@Transient
		public Integer getBranchQualifiedNum(){
			int total = 0;
			for (int i = 0; i < this.getBranchList().size(); i++) {
				if("不合格".equals(this.getBranchList().get(i).getQuaLevel())){
					total++;
				}
			}
			return MathsUtils.sub(this.getBranchList().size(),total);
		}
		
		//获得单位工程合格率
		@Transient
		public Double  getBranchQualifiedPro(){
			return MathsUtils.div("2",this.getBranchQualifiedNum(),this.getBranchList().size());
		}

		public void addBranch(Branch branch) {
			this.branchList.add(branch);
		}

		
		
	
}
